﻿using System;
using System.Windows.Forms;

namespace MyPaint
{
    public partial class SnapTool : UserControl
    {
        /// <summary>
        /// 截图指令的处理事件
        /// </summary>
        public ImageDelegate SnapEvent {  get; set; }

        public SnapTool()
        {
            InitializeComponent();

            SetToolTips();

            butRejustRectangleWidth.MouseClick += MouseClickEvent;
            butRejustCircleWidth.MouseClick += MouseClickEvent;
            butRedArrow.MouseClick += MouseClickEvent;
            btnDrawLineTo.MouseClick += MouseClickEvent;
            btnDrawMosaic.MouseClick += MouseClickEvent;
            btnWriting.MouseClick += MouseClickEvent;
            btnDrawUndo.MouseClick += MouseClickEvent;
            btnDrawSave.MouseClick += MouseClickEvent;
            btnDrawCancel.MouseClick += MouseClickEvent;
            btnDrawDone.MouseClick += MouseClickEvent;
        }

        #region 批量设置悬浮文字提示

        private ToolTip toolTip;

        /// <summary>
        /// 批量设置悬浮文字
        /// </summary>
        private void SetToolTips()
        {
            this.components = new System.ComponentModel.Container();
            toolTip = new ToolTip(this.components);

            foreach (Control ctrl in this.flpPanel.Controls)
            {
                toolTip.SetToolTip(ctrl, SwitchBtnTextForToolTip(ctrl));
            }
        }

        /// <summary>
        /// 根据控件名称返回字符串
        /// </summary>
        /// <param name="ctrl"></param>
        /// <returns></returns>
        private string SwitchBtnTextForToolTip(Control ctrl)
        {
            string result = "";
            switch (ctrl.Name)
            {
                case "butRejustRectangleWidth":
                    result = "方框";
                    break;
                case "butRejustCircleWidth":
                    result = "椭圆";
                    break;
                case "butRedArrow":
                    result = "箭头";
                    break;
                case "btnDrawLineTo":
                    result = "画笔";
                    break;
                case "btnDrawMosaic":
                    result = "马赛克";
                    break;
                case "btnWriting":
                    result = "文字";
                    break;
                case "labelL":
                    result = "";
                    break;
                case "btnDrawUndo":
                    result = "撤销";
                    break;
                case "btnDrawSave":
                    result = "保存";
                    break;
                case "btnDrawCancel":
                    result = "退出";
                    break;
                case "btnDrawDone":
                    result = "完成";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }

        #endregion


        private void MouseClickEvent(object sender, MouseEventArgs e)
        {
            var btn = sender as Button;
            SnapEvent?.Invoke(btn.Name);
        }
    }
}
